var params = {};
var defaultnextPageSize = 10;
var currentPage = 1;
var pageSize = defaultnextPageSize;

$(function(){
	 var id=localStorage.getItem("rowId");
	 localStorage.removeItem("rowId");
	 queryNextParams(id);
});

function queryNextParams(id){
	params.id=id;
	params.currentPage = currentPage;
	params.pageSize = pageSize;
	$.ajax({
		url: webUrl+'sysParams/getNextSysParamsById.do',
		type:'post',
		data:params
	}).done(function(data){
		var result = data.bo;
		//alert(JSON.stringify(result));
		var pager = {};
		$('#sysParamsNext').datagrid({
			fitColumns:true,
			singleSelect:true,
			pagination:true,
			remoteSort:false,
			multiSort:true,
			loadMsg:"数据加载中，请稍后……",
			data:result.list,
			columns:[[
			          {field:'_itemNo1',title:'序号',align:'center',width:10,formatter:formatId},
			          {field:'typeCode',title:'类型编码',width:50,sortable:true},
			          {field:'param_key',title:'参数健',width:60,sortable:true},
			          {field:'paramValue',title:'参数值',width:60,sortable:true},
			          {field:'paramLevel',title:'参数层级',sortable:true},
			          {field:'status',title:'状态标识',sortable:true},
			          /*{field:'last_updated_date',title:'更新时间',sortable:true,formatter:formatTime},*/
			          {field:'_operate',title:'操作',formatter:formatOper},
			      ]],
			      onSortColumn: function (sort, order) {
			    	  setPager(pager,result.total);
         }
		});
		var pager = $('#sysParamsNext').datagrid().datagrid('getPager');	// get the pager of datagrid
		setPager(pager,result.total);
		$('.addicon').on('click',addNextParam);
		$('.playicon').on('click',onchange);
		$('.delicon').on('click',deleteSysparam);
	});
}

function deleteSysparam(){
	var id = $(this).attr('row-id');
	var paramLevel=$(this).attr('paramLevel');
	var tips = '确认是否删除?';
	deleteTips(id,tips,paramLevel);
}

function deleteTips(id,tips,paramLevel){
	$("#tipsInfo").html('<b class="sighicon"></b>'+tips);
		new Dialog({
			target:'#tipsbox',
			width:300,
			height:160,
			showYesBtn:true,
			showNoBtn:true,
			yesFn:function(){
				deleteSysParamData(id,paramLevel);
			},
			noFn:function(){}
			}).show();
}

function deleteSysParamData(id,paramLevel){
	$.ajax({
		url:webUrl+'sysParams/deleteSysParamById.do',
		type:'post',
		data:{id:id}
	}).done(function(data){
		$('.main_panel').load(webUrl+"public/page/sysParams/nextParams.html");
		
	});
}

function onchange(){
	var id = $(this).attr('row-id');
	localStorage.setItem("rowId", id);
	$('.main_panel').load(webUrl+"public/page/sysParams/nextParams.html");
}

function addNextParam(){
	var id = $(this).attr('row-id');
	localStorage.setItem("rowId", id);
	$('.main_panel').load(webUrl+"public/page/sysParams/addNextParams.html");
}

var formatOper = function(val,row,index){
	return '<a href="#" class="playicon  ml10" row-id="'+row.id+'" data-tipso="下一级"></a> <a href="#" class="addicon  ml10" row-id="'+row.id+'" data-tipso="新增下一级"></a>  <a href="#" class="dealicon  ml10"  row-id="'+row.id+'" data-tipso="编辑"></a> <a href="#;"  class="delicon  ml10" paramLevel="'+row.paramLevel+'" row-id="'+row.id+'" data-tipso="删除"></a>';
}

function setPager(pager,total){
	pager.pagination({
		total:total,
		pageNumber:currentPage,
	    pageSize:defaultnextPageSize,
	    layout:['first','prev','links','next','last'],
	    onSelectPage:function(cpage, psize){
	    	currentPage=cpage;
	    	pageSize=psize;
	    	$('.main_panel').load(webUrl+"public/page/sysParams/params.html");
		}
	});
}

$("ul.tabtit").on("click",function(event){
	$('.main_panel').load(webUrl+"public/page/sysParams/params.html");
});
